lets_plot.geo_data.geocode¶
-
lets_plot.geo_data.geocode(level=None, names=None, countries=None, states=None, counties=None, scope=None) → lets_plot.geo_data.geocoder.NamesGeocoder¶ Create a Geocoder. Allows to refine ambiguous request with where() method, scope that limits area of geocoding or with parents.
- Parameters
level ({‘country’, ‘state’, ‘county’, ‘city’}) – The level of administrative division. Autodetection by default.
names (list or str) – Names of objects to be geocoded. For ‘state’ level: ‘US-48’ returns continental part of United States (48 states) in a compact form.
countries (list) – Parent countries. Should have same size as names. Can contain strings or Geocoder objects.
states (list) – Parent states. Should have same size as names. Can contain strings or Geocoder objects.
counties (list) – Parent counties. Should have same size as names. Can contain strings or Geocoder objects.
scope (str or Geocoder) – Limits area of geocoding. If parent country is set then error will be generated. If type is a string - geoobject should have geocoded scope in parents. If type is a Geocoder - geoobject should have geocoded scope in parents. Scope should contain only one entry.
- Returns
Geocoder object specification.
- Return type
NamesGeocoder
Examples
1 2 3 4 5 6 7
from IPython.display import display from lets_plot import * from lets_plot.geo_data import * LetsPlot.setup_html() states = geocode('state').scope('Italy').get_boundaries(6) display(states.head()) ggplot() + geom_map(data=states)
The geodata is provided by © OpenStreetMap contributors and is made available here under the Open Database License (ODbL).
state found name geometry 0 Marche Marche MULTIPOLYGON (((12.98584 42.89206, 12.98584 42... 1 Abruzzo Abruzzo MULTIPOLYGON (((14.12842 41.73853, 14.12842 41... 2 Sicilia Sicilia MULTIPOLYGON (((12.59033 35.51434, 12.59033 35... 3 Puglia Puglia MULTIPOLYGON (((15.46875 42.11452, 15.49072 42... 4 Basilicata Basilicata MULTIPOLYGON (((16.74316 40.21244, 16.74316 40... 1 2 3 4 5 6 7 8 9 10 11 12
from IPython.display import display from lets_plot import * from lets_plot.geo_data import * LetsPlot.setup_html() states = geocode(level='state', scope='US').get_geocodes() display(states.head()) names = ['York'] * len(states.state) cities = geocode(names=names, states=states.state).ignore_not_found().get_centroids() display(cities.head()) ggplot() + \ geom_livemap() + \ geom_point(data=cities, tooltips=layer_tooltips().line('@{found name}'))
id state found name 0 121519 Vermont Vermont 1 122631 Massachusetts Massachusetts 2 122641 New York New York 3 127025 Maine Maine 4 134427 New Hampshire New Hampshire city found name state geometry 0 York New York New York POINT (-73.86737 40.68470) 1 York York Maine POINT (-70.67916 43.17855) 2 York Little York Illinois POINT (-90.74261 41.01002) 3 York York Nebraska POINT (-97.59012 40.86006) 4 York York North Dakota POINT (-99.57356 48.31308)